
#ifndef __NORFLASH_H__
#define __NORFLASH_H__

#include <stdint.h>

#define NORFLASH_FLASH_SIZE   (4 * 1024 * 1024)
#define NORFLASH_BLOCK_SIZE   (0x10000)
#define NORFLASH_SECTOR_SIZE  (0x1000)
#define NORFLASH_PAGE_SIZE    (0x100)

#define NORFLASH_ERROR        (-1)
#define NORFLASH_OK           (0)

#define NORFLASH_WRITE_ENABLE (0x06)
#define NORFLASH_READ         (0x03)
#define NORFLASH_PAGE_PROGRAM (0x02)
#define NORFLASH_STATUS_REG1  (0x05)
#define NORFLASH_ENABLE_RESET (0x66)
#define NORFLASH_RESET_DEVICE (0x99)
#define NORFLASH_DEVICE_ID    (0x9F)
#define NORFLASH_ID_NUMBER    (0x4b)
#define NORFLASH_ERASE_SECTOR (0x20)
#define NORFLASH_ERASE_BLOCK  (0xd8)
#define NORFLASH_ERASE_CHIP   (0xc7)

#define NORFLASH_Enable       GPIO_PIN_RESET
#define NORFLASH_Disable      GPIO_PIN_SET

void NORFLASH_Reset(void);
void NORFLASH_DeviceID(uint8_t *v);
int NORFLASH_EraseSector(uint32_t SectorAddress);
int NORFLASH_EraseBlock(uint32_t BlackAddress);
int NORFLASH_EraseChip(void);
int NORFLASH_Read256B(uint8_t *pData, uint32_t ReadAddr);
int NORFLASH_Read(uint8_t *pData, uint32_t ReadAddr, uint32_t Size);
int NORFLASH_PageProgram(uint8_t *pData, uint32_t WriteAddr, uint32_t Size);
int NORFLASH_Write(uint8_t *pData, uint32_t WriteAddr, uint32_t Size);

#endif
